package de.herberlin.webapp.core;

import java.io.Serializable;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.herberlin.webapp.text.Page;

public abstract class AbstractAction implements ActionBean, Serializable {

	
	protected static final long serialVersionUID = 1L;

	private ActionBeanContext context;
	protected Log logger = LogFactory.getLog(getClass());

	/** 
	 * @see net.sourceforge.stripes.action.ActionBean#getContext()
	 */
	public ActionBeanContext getContext() {
		return context;
	}

	/** 
	 * @see net.sourceforge.stripes.action.ActionBean#setContext(net.sourceforge.stripes.action.ActionBeanContext)
	 */
	public void setContext(ActionBeanContext context) {
		this.context=context;
	}

	public String getPageId() {
		String result=(String)getContext().getRequest().getAttribute("pageId");
		if (result==null) {
			result=getContext().getRequest().getParameter("pageId");
		}
		return result;
	}
	
	public String getUrl(String pageId) {
		return "/"+pageId+".html";
	}
	public String getUrl(Page page) {
		if (page==null) {
			throw new AppException("Page must not be null!");
		}
		return getUrl(page.getId());
	}
}
